package com.ruoyi.user.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.user.domain.TbUser;
import com.ruoyi.user.service.ITbUser1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 管理用户Controller
 * 
 * @author ruoyi
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/user1/user1")
public class TbUserController1 extends BaseController
{
    @Autowired
    private ITbUser1Service tbUserService;

    /**
     * 查询管理用户列表
     */
    @PreAuthorize("@ss.hasPermi('user1:user1:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbUser tbUser)
    {
        startPage();
        List<TbUser> list = tbUserService.selectTbUserList(tbUser);
        return getDataTable(list);
    }

    /**
     * 导出管理用户列表
     */
    @PreAuthorize("@ss.hasPermi('user1:user1:export')")
    @Log(title = "管理用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbUser tbUser)
    {
        List<TbUser> list = tbUserService.selectTbUserList(tbUser);
        ExcelUtil<TbUser> util = new ExcelUtil<TbUser>(TbUser.class);
        util.exportExcel(response, list, "管理用户数据");
    }

    /**
     * 获取管理用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('user1:user1:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(tbUserService.selectTbUserByUserId(userId));
    }

    /**
     * 新增管理用户
     */
    @PreAuthorize("@ss.hasPermi('user1:user1:add')")
    @Log(title = "管理用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbUser tbUser)
    {
        return toAjax(tbUserService.insertTbUser(tbUser));
    }

    /**
     * 修改管理用户
     */
    @PreAuthorize("@ss.hasPermi('user1:user1:edit')")
    @Log(title = "管理用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbUser tbUser)
    {
        return toAjax(tbUserService.updateTbUser(tbUser));
    }

    /**
     * 删除管理用户
     */
    @PreAuthorize("@ss.hasPermi('user1:user1:remove')")
    @Log(title = "管理用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(tbUserService.deleteTbUserByUserIds(userIds));
    }
}
